<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p></p>
    <p></p>
</body>
<script>
    // 构造方法
    function Student(name,age) {
        this.name = name;
        this.age = age;
    }

    // 通过构造函数创建对象
    let stu1 = new Student("徐容",20);
    let stu2 = new Student("奉先",35);

    // prototype：构造函数的属性，获取构造方法的原型对象。
    // __proto__（非标准属性）：对象的属性，获取对象的原型对象。推荐使用Object.getPrototypeOf(object)代替

    let p1 = Student.prototype;
    let p2 = stu1.__proto__;
    let p3 = Object.getPrototypeOf(stu2);

    console.log(p1 === p2); // true
    console.log(p3 === p2); // true
    console.log("p1 = ",p1);

    let p4 = p1.__proto__;
    console.log("p4 = ",p4);

    let p5 = Object.prototype;
    console.log(p4 === p5);

    console.log(stu2 instanceof Object); // true


    // constructor
    console.log(Student == p1.constructor); // true
    console.log(stu1.constructor.prototype == Student.prototype); // true

    // 看看原型对象的构造函数
    console.log(p1.constructor == Student); // true

    // Object的原型对象，是不是又有原型对象呢？
    console.log(Object.prototype.__proto__); // null

    Object.prototype.sayHello = function() {
        console.log("Hello");
    }

    stu1.sayHello();
    p4.sayHello();
    window.sayHello();
    document.querySelector("body").sayHello();
    document.querySelectorAll("p").sayHello();
</script>
</html>